package com.goldwind.accompany.controller;

import com.goldwind.accompany.service.impl.AccompanyImpl;
import com.goldwind.pojo.AccompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/accompanys")
public class AccompanyController {
    @Autowired
    private AccompanyImpl accompanyImpl;

    @GetMapping("/all")
    public Result selectAll() {
        List<AccompanyService> list=accompanyImpl.selectAll();
        Integer code=list!=null?Code.selectALL_OK:Code.selectALL_ERR;
        String msg=list!=null?"查询成功":"查询失败";

        return new Result(list,code,msg);
    }

    @GetMapping("/search")
    public Result selectByConditions(
            @RequestParam(required = false) String gameType,
            @RequestParam(required = false) String serviceType,
            @RequestParam(required = false) Double minPrice,
            @RequestParam(required = false) Double maxPrice,
            @RequestParam(required = false) String keyword,
            @RequestParam(required = false) Integer status ,
            @RequestParam(required = false) Integer userId){

        List <AccompanyService> list=accompanyImpl.selectByConditions(
                gameType, serviceType, minPrice, maxPrice, keyword, status, userId
        );

        Integer code=list!=null?Code.selectByConditions_OK:Code.selectByConditions_ERR;
        String msg=list!=null?"查询成功":"查询失败";
        return new Result(list,code,msg);
    }

    @PostMapping
    public Result insert(@RequestBody AccompanyService service) {
        boolean flag=accompanyImpl.insert(service);
        return new Result(flag?Code.insert_OK:Code.insert_ERR,flag);
    }

    @PutMapping
    public Result update(@RequestBody AccompanyService service) {
        boolean flag=accompanyImpl.update(service);
        return new Result(flag?Code.update_OK:Code.update_ERR,flag);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable int id) {
        boolean flag=accompanyImpl.delete(id);
        return new Result(flag?Code.delete_OK:Code.delete_ERR,flag);
    }


}
